<?php

namespace App\Models;

class BannerModel
{
    /**
     * 轮播图列表
     * entry
     * return array
     * */
    public static function getBannerList($conn,$position){
        if(!$position){
            $position = 'index';
        }
        $bannerSql="SELECT `id`, `type`, `img`, `link`, `position`, `time`, `status`,`bg_color` FROM `banner` WHERE `position` ='$position' and `status` = 1";
        return $conn->readConn($bannerSql, true);
    }
    /**
     * 添加轮播图
     * entry
     * return array
     * */
    public static function insertBanner($conn,$BannerExample){
        $fundsSql ="INSERT INTO `banner`(`type`, `img`, `link`, `position`, `bg_color`, `status`) VALUES ($BannerExample->type,'$BannerExample->img','$BannerExample->link','$BannerExample->position','$BannerExample->bg_color',$BannerExample->status)";
        return $conn->executeConn($fundsSql);
    }
    /**
     * 修改轮播图可添加字段
     * entry BannerExample
     * return int
     * */
    public static function upBannerInside($conn,$BannerExample){
        $joinSql="";
        if($BannerExample->type !=null){
            $joinSql.=" `type` = '$BannerExample->type',";
        }
        if($BannerExample->img !=null){
            $joinSql.=" `img` = '$BannerExample->img',";
        }
        if($BannerExample->link !=null){
            $joinSql.=" `link` = '$BannerExample->link',";
        }
        if($BannerExample->position !=null){
            $joinSql.=" `position` = '$BannerExample->position',";
        }
        if($BannerExample->bg_color !=null){
            $joinSql.=" `bg_color` = '$BannerExample->bg_color',";
        }
        if($BannerExample->status !=null){
            $joinSql.=" `status` = $BannerExample->status,";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `banner` SET $innerJoin WHERE `id` = '$BannerExample->id'";
            return $conn->executeConn($upUserSql);
        }
    }
}